import VueRouter from "vue-router";
import userFrame from "_c/userFrame/userFrame.vue";
import Token from "@/utils/token";

// 解决连续多次点击路由报错问题
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

const routes = [
  {
    path: "/user",
    component: userFrame,
    children: [
      {
        path: "",
        name: "userhome",
        meta: {
          title: "控制台",
          navIndex: 0,
          innerIndex: null,
        },
        component: () => import("./views/home/home.vue"),
      },
      {
        path: "mydn",
        name: "myDNList",
        meta: {
          title: "我的域名",
          navIndex: 1,
          innerActive: 0,
          tabIndex: 0,
          overhidden: true
        },
        component: () => import("./views/dnManagement/myDN/myDN"),
      },
      {
        path: "mydnNew",
        name: "myDNList",
        meta: {
          title: "我的域名",
          navIndex: 1,
          innerActive: 0,
          tabIndex: 0,
          overhidden: true
        },
        component: () => import("./views/dnManagement/myDN/myDNNew"),
      },
      {
        path: "/user/mydn/details/:domainId?/:title?/:isOutside?",
        name: "myDNDetails",
        meta: {
          title: "域名详情",
          navIndex: 1,
          innerActive: 0,
          tabIndex: 0,
        },
        component: () => import("./views/dnManagement/myDN/dnDetail"),
      },
      {
        path: "analysis",
        component: () => import("./views/dnManagement/analysis/main"),
        children: [
          {
            path: "/user/mydn/batchAnalysis/:domainId?/:title?",
            name: "batchAnalysis",
            meta: {
              title: "解析设置",
              navIndex: 1,
              innerActive: 0,
              tabIndex: 0,
              subTitle: "",
            },
            component: () =>
              import("./views/dnManagement/analysis/batchAnalysis"),
          },
          {
            path: "/user/mydn/record/:domainId?/:title?",
            name: "record",
            meta: {
              title: "操作记录",
              navIndex: 1,
              innerActive: 0,
              tabIndex: 1,
              subTitle: "",
            },
            component: () => import("./views/dnManagement/analysis/record"),
          },
        ],
      },
      {
        path: "dns",
        name: "dns",
        meta: {
          title: "DNS设置",
          navIndex: 1,
          innerActive: 0,
          tabIndex: 0,
        },
        component: () => import("./views/dnManagement/dns/dns"),
      },
      {
        path: "template",
        component: () =>
          import("./views/dnManagement/myTemplate/myTemplate.vue"),
        children: [
          {
            path: "",
            name: "templatelist",
            meta: {
              title: "我的模板",
              navIndex: 1,
              innerActive: 1,
              tabIndex: 0,
              keepAlive: true,
            },
            component: () => import("@/pages/user/views/dnManagement/myTemplate/list.vue"),
          },
          {
            path: "add",
            name: "templateadd",
            meta: {
              title: "添加模板",
              navIndex: 1,
              innerActive: 1,
              tabIndex: 1,
            },
            component: () => import("@/pages/user/views/dnManagement/myTemplate/add.vue"),
          },
          {
            path: "default",
            name: "templatedefault",
            meta: {
              title: "设置默认列表",
              navIndex: 1,
              innerActive: 1,
              tabIndex: 2,
            },
            component: () =>
              import("@/pages/user/views/dnManagement/myTemplate/default.vue"),
          },
          {
            path: "transfer",
            name: "templatetransfer",
            meta: {
              title: "模板过户",
              navIndex: 1,
              innerActive: 1,
              tabIndex: 3,
            },
            component: () =>
              import("@/pages/user/views/dnManagement/myTemplate/transfer.vue"),
          },
          {
            path: "transferList",
            name: "templatetransferList",
            meta: {
              title: "模板过户记录",
              navIndex: 1,
              innerActive: 1,
              tabIndex: 4,
              overhidden: true
            },
            component: () =>
              import("@/pages/user/views/dnManagement/myTemplate/transferList.vue"),
          }
        ],
      },
      {
        path: "templateDetails",
        name: "templateDetails",
        meta: {
          title: "模板详情",
          navIndex: 1,
          innerActive: 1,
          tabIndex: 0,
        },
        component: () => import("./views/dnManagement/myTemplate/templateDetails.vue"),
      },
      {
        path: "transferout",
        component: () =>
          import("./views/dnManagement/dnTransferOut/dnTransferOut.vue"),
        children: [
          {
            path: "",
            name: "transferoutform",
            meta: {
              title: "域名转出",
              navIndex: 1,
              innerActive: 2,
              tabIndex: 0,
            },
            component: () =>
              import("./views/dnManagement/dnTransferOut/form.vue"),
          },
          {
            path: "record",
            name: "transferoutrecord",
            meta: {
              title: "域名转出记录",
              navIndex: 1,
              innerActive: 2,
              tabIndex: 1,
            },
            component: () =>
              import("./views/dnManagement/dnTransferOut/record.vue"),
          },
        ],
      },
      {
        path: "transferin",
        component: () =>
          import("./views/dnManagement/dnTransferIn/dnTransferIn.vue"),
        children: [
          {
            path: "",
            name: "transferinform",
            meta: {
              title: "域名转入",
              navIndex: 1,
              innerActive: 3,
              tabIndex: 0,
            },
            component: () =>
              import("./views/dnManagement/dnTransferIn/form.vue"),
          },
          {
            path: "record",
            name: "transferinrecord",
            meta: {
              title: "域名转入",
              navIndex: 1,
              innerActive: 3,
              tabIndex: 1,
            },
            component: () =>
              import("./views/dnManagement/dnTransferIn/record.vue"),
          },
        ],
      },
      {
        path: "dnpush",
        component: () => import("./views/dnManagement/dnPush/dnPush.vue"),
        children: [
          {
            path: "",
            name: "dnpushform",
            meta: {
              title: "域名PUSH",
              navIndex: 1,
              innerActive: 4,
              tabIndex: 0,
            },
            component: () => import("./views/dnManagement/dnPush/form.vue"),
          },
          {
            path: "receive",
            name: "dnpushreceive",
            meta: {
              title: "收到的请求",
              navIndex: 1,
              innerActive: 4,
              tabIndex: 1,
            },
            component: () => import("./views/dnManagement/dnPush/receive.vue"),
          },
          {
            path: "sent",
            name: "dnpushsent",
            meta: {
              title: "发出的请求",
              navIndex: 1,
              innerActive: 4,
              tabIndex: 2,
            },
            component: () => import("./views/dnManagement/dnPush/sent.vue"),
          },
        ],
      },
      {
        path: "myorder",
        name: "myorder",
        meta: {
          title: "域名订单",
          navIndex: 1,
          innerActive: 5,
          tabIndex: 0,
        },
        component: () => import("./views/dnManagement/myOrder/myOrder.vue"),
      },
      {
        path: "orderdetail",
        name: "orderdetail",
        meta: {
          title: "订单详情",
          navIndex: 1,
          innerActive: 5,
          tabIndex: 0,
        },
        component: () => import("./views/dnManagement/myOrder/orderDetail.vue"),
      },
      {
        path: "batchanalysis",
        component: () => import("./views/dnManagement/batchanalysis/batchanalysis.vue"),
        children: [
          {
            path: "",
            name: "batchanalysisfrom",
            meta: {
              title: "批量解析",
              navIndex: 1,
              innerActive: 6,
              tabIndex: 0,
            },
            component: () => import("./views/dnManagement/batchanalysis/form.vue"),
          },
          {
            path: "senioranalysis",
            name: "senioranalysis",
            meta: {
              title: "高级批量解析",
              navIndex: 1,
              innerActive: 6,
              tabIndex: 1,
            },
            component: () => import("./views/dnManagement/batchanalysis/senioranalysis.vue"),
          }
        ],
      },
      {
        path: "batchDns",
        component: () => import("./views/dnManagement/batchDns/batchDns.vue"),
        children: [
          {
            path: "",
            name: "batchDns",
            meta: {
              title: "DNS设置",
              navIndex: 1,
              innerActive: 7,
              tabIndex: 0,
            },
            component: () => import("./views/dnManagement/batchDns/form.vue"),
          },
          {
            path: "dnsLogs",
            name: "dnsLogs",
            meta: {
              title: "DNS设置记录",
              navIndex: 1,
              innerActive: 7,
              tabIndex: 1,
            },
            component: () => import("./views/dnManagement/batchDns/dnsLogs.vue"),
          }
        ],
      },
      {
        path: "mybookings",
        name: "mybookings",
        meta: {
          title: "我的预订",
          navIndex: 2,
          innerActive: 2,
          tabIndex: 0,
        },
        component: () =>
          import("./views/rushRegistration/myBookings/myBookings.vue"),
      },
      {
        path: "reminder",
        component: () =>
          import("./views/rushRegistration/reminder/reminder.vue"),
        children: [
          {
            path: "",
            name: "reminderlist",
            meta: {
              title: "预订提醒列表",
              navIndex: 2,
              innerActive: 3,
              tabIndex: 0,
              keepAlive: true,
            },
            component: () =>
              import("./views/rushRegistration/reminder/list.vue"),
          },
          {
            path: "setting",
            name: "remindersetting",
            meta: {
              title: "添加预订提醒",
              navIndex: 2,
              innerActive: 3,
              tabIndex: 1,
            },
            component: () =>
              import("./views/rushRegistration/reminder/setting.vue"),
          },
        ],
      },
      {
        path: "mybiddings",
        name: "mybiddings",
        meta: {
          title: "我的竞价",
          navIndex: 3,
          innerActive: 1,
          tabIndex: 0,
          overhidden: true
        },
        component: () =>
          import("./views/rushRegistration/myBiddings/myBiddings.vue"),
      },
      {
        path: "mywinnings",
        name: "mywinnings",
        meta: {
          title: "我的得标",
          navIndex: 3,
          innerActive: 2,
          tabIndex: 0,
        },
        component: () =>
          import("./views/rushRegistration/myWinnings/myWinnings.vue"),
      },
      {
        path: "dnsell",
        name: "dnsell",
        meta: {
          title: "出售域名",
          navIndex: 4,
          innerActive: 0,
          tabIndex: 0,
        },
        component: () => import("./views/bopManagement/dnSell/dnSell.vue"),
      },
      {
        path: "release",
        component: () => import("./views/bopManagement/release/release.vue"),
        children: [
          {
            path: "",
            name: "release",
            meta: {
              title: "释放域名",
              navIndex: 4,
              innerActive: 1,
              tabIndex: 0,
            },
            component: () => import("./views/bopManagement/release/form.vue"),
          },
          {
            path: "record",
            name: "releaserecord",
            meta: {
              title: "高级批量解析",
              navIndex: 4,
              innerActive: 1,
              tabIndex: 1,
            },
            component: () => import("./views/bopManagement/release/record.vue"),
          }
        ],
      },
      {
        path: "mybopdn",
        name: "mybopdn",
        meta: {
          title: "发布的一口价",
          navIndex: 4,
          innerActive: 2,
          tabIndex: 0,
          overhidden: true
        },
        component: () => import("./views/bopManagement/mybopDn/mybopDn.vue"),
      },
      {
        path: "successbop",
        name: "successbop",
        meta: {
          title: "购买的一口价",
          navIndex: 5,
          innerActive: 0,
          tabIndex: 0,
        },
        component: () =>
          import("./views/bopManagement/successbop/successbop.vue"),
      },
	  {
	    path: "entrust",
	    name: "entrust",
	    meta: {
	      title: "我的委托",
	      navIndex: 5,
	      innerActive: 1,
	      tabIndex: 0,
	    },
	    component: () =>
	      import("./views/bopManagement/successbop/entrust.vue"),
	  },
      {
        path: "bopsetting",
        name: "bopsetting",
        meta: {
          title: "设置一口价出售",
          navIndex: 4,
          innerActive: 3,
          tabIndex: 0,
        },
        component: () => import("./views/bopManagement/setting/setting.vue"),
      },
      {
        path: "purchasing",
        name: "purchasing",
        meta: {
          title: "域名委托代购记录",
          navIndex: 6,
          innerActive: 1,
          tabIndex: 0,
        },
        component: () =>
          import("./views/Intermediary/Purchasing/Purchasing.vue"),
      },
      {
        path: "sell",
        name: "sell",
        meta: {
          title: "域名委托出售记录",
          navIndex: 6,
          innerActive: 2,
          tabIndex: 0,
        },
        component: () => import("./views/Intermediary/sell/sell.vue"),
      },
      // {
      //   path: "tmpurchasing",
      //   name: "tmpurchasing",
      //   meta: {
      //     title: "商标委托代购记录",
      //     navIndex: 7,
      //     innerActive: 1,
      //     tabIndex: 0,
      //   },
      //   component: () => import("./views/trademark/Purchasing/Purchasing.vue"),
      // },
      // {
      //   path: "tmsell",
      //   name: "tmsell",
      //   meta: {
      //     title: "商标委托出售记录",
      //     navIndex: 7,
      //     innerActive: 2,
      //     tabIndex: 0,
      //   },
      //   component: () => import("./views/trademark/sell/sell.vue"),
      // },
      {
        path: "account",
        name: "account",
        meta: {
          title: "账户信息",
          navIndex: 6,
          innerActive: 0,
          tabIndex: 0,
        },
        component: () => import("./views/finance/account/index.vue"),
      },
      {
        path: "recharge",
        name: "recharge",
        meta: {
          title: "在线充值",
          navIndex: 6,
          innerActive: 0,
          tabIndex: 0,
        },
        component: () => import("./views/finance/account/recharge.vue"),
      },
      {
        path: "discount",
        name: "discount",
        meta: {
          title: "折扣统计",
          navIndex: 6,
          innerActive: 1,
          tabIndex: 0,
        },
        component: () => import("./views/finance/account/discount.vue"),
      },
      {
        path: "cashout",
        name: "cashout",
        meta: {
          title: "资金提现",
          navIndex: 6,
          innerActive: 0,
          tabIndex: 0,
        },
        component: () => import("./views/finance/account/cashOut.vue"),
      },
      {
        path: "capitaldetails",
        name: "capitaldetails",
        meta: {
          title: "资金明细",
          navIndex: 6,
          innerActive: 2,
          tabIndex: 0,
          overhidden: true
        },
        component: () =>
          import("./views/finance/capitalDetails/capitalDetails.vue"),
      },
      /*{
        path: "freezedetails",
        name: "freezedetails",
        meta: {
          title: "冻结明细",
          navIndex: 6,
          innerActive: 3,
          tabIndex: 0,
        },
        component: () =>
          import("./views/finance/freezeDetails/freezeDetails.vue"),
      },*/
      {
        path: "invoice",
        component: () => import("./views/finance/invoice/invoice.vue"),
        children: [
          {
            path: "",
            name: "invoiceManagement",
            meta: {
              title: "发票管理",
              navIndex: 6,
              innerActive: 3,
              tabIndex: 0,
              overhidden: true
            },
            component: () => import("./views/finance/invoice/management.vue"),
          },
          {
            path: "detail",
            name: "invoiceDetail",
            meta: {
              title: "发票详情",
              navIndex: 6,
              innerActive: 3,
              tabIndex: 0,
            },
            component: () => import("./views/finance/invoice/detail.vue"),
          },
          {
            path: "apply",
            name: "invoiceApply",
            meta: {
              title: "发票申请",
              navIndex: 6,
              innerActive: 3,
              tabIndex: 1,
              overhidden: true
            },
            component: () => import("./views/finance/invoice/apply.vue"),
          },
          {
            path: "info",
            name: "invoiceInfo",
            meta: {
              title: "发票信息",
              navIndex: 6,
              innerActive: 3,
              tabIndex: 2
            },
            component: () => import("./views/finance/invoice/info.vue"),
          },
        ],
      },
/*      {
        path: "mypoints",
        component: () => import("./views/pointsOrder/myPoints.vue"),
        children: [
          {
            path: "",
            name: "pointsdetail",
            meta: {
              title: "积分明细",
              navIndex: 7,
              innerActive: 3,
              tabIndex: 0,
            },
            component: () => import("./views/pointsOrder/pointsDetail.vue"),
          },
          {
            path: "pointsorder",
            name: "pointsorder",
            meta: {
              title: "积分订单",
              navIndex: 7,
              innerActive: 4,
              tabIndex: 2,
            },
            component: () => import("./views/pointsOrder/pointsOrder.vue"),
          },
        ],
      },*/
      /*{
        path: "orderdetail",
        name: "orderdetail",
        meta: {
          title: "积分订单详情",
          navIndex: 7,
          innerActive: 4,
          tabIndex: 0,
        },
        component: () => import("./views/pointsOrder/orderDetail.vue"),
      },*/
      {
        path: "personalData",
        name: "personalData",
        meta: {
          title: "个人资料",
          navIndex: 7,
          innerActive: 0,
          tabIndex: 0,
        },
        component: () =>
          import("./views/account/personalData/personalData.vue"),
      },
      {
        path: "security",
        name: "security",
        meta: {
          title: "安全中心",
          navIndex: 7,
          innerActive: 1,
          tabIndex: 0,
        },
        component: () => import("./views/account/security/security.vue"),
      },
      {
        path: "changepw",
        name: "changepw",
        meta: {
          title: "修改密码",
          navIndex: 7,
          innerActive: 1,
          tabIndex: 0,
        },
        component: () => import("./views/account/security/changePassword.vue"),
      },
      {
        path: "certification",
        name: "certification",
        meta: {
          title: "我的认证",
          navIndex: 7,
          innerActive: 2,
          tabIndex: 0,
        },
        component: () =>
          import("./views/account/certification/certification.vue"),
      },
      {
        path: "personalc",
        name: "personalc",
        meta: {
          title: "个人认证",
          navIndex: 7,
          innerActive: 2,
          tabIndex: 0,
        },
        component: () => import("./views/account/certification/personalc.vue"),
      },
      {
        path: "companyc",
        name: "companyc",
        meta: {
          title: "企业认证",
          navIndex: 7,
          innerActive: 2,
          tabIndex: 0,
        },
        component: () => import("./views/account/certification/companyc.vue"),
      },
      {
        path: "emailc",
        name: "emailc",
        meta: {
          title: "邮箱认证",
          navIndex: 7,
          innerActive: 2,
          tabIndex: 0,
        },
        component: () => import("./views/account/certification/emailc.vue"),
      },
     /* {
        path: "myapplication",
        component: () => import("./views/account/myapplication/myapplication.vue"),
        children: [
          {
            path: "",
            name: "myapplicationform",
            meta: {
              title: "申请成为代理商",
              navIndex: 7,
              innerActive: 3,
              tabIndex: 0,
            },
            component: () => import("./views/account/myapplication/form.vue"),
          },
          {
            path: "record",
            name: "myapplicationrecord",
            meta: {
              title: "代理商申请记录",
              navIndex: 7,
              innerActive: 3,
              tabIndex: 1,
              overhidden: true
            },
            component: () => import("./views/account/myapplication/record.vue"),
          },
        ],
      },*/
      {
        path: "noticeSetting",
        name: "noticeSetting",
        meta: {
          title: "通知设置",
          navIndex: 7,
          innerActive: 3,
          tabIndex: 0,
        },
        component: () => import("./views/account/noticeSetting/noticeSetting.vue"),
      },
      {
        path: "mail",
        name: "mail",
        meta: {
          title: "站内信",
          navIndex: 7,
          innerActive: 4,
          tabIndex: 0,
          overhidden: true
        },
        component: () => import("./views/account/mail/mail.vue"),
      },
      {
        path: "securitylog",
        name: "securitylog",
        meta: {
          title: "登录日志",
          navIndex: 7,
          innerActive: 5,
          tabIndex: 0,
        },
        component: () => import("./views/account/securityLog/securityLog.vue"),
      },

    ],
  },
  // 错误页面
  // {
  //   path: "*",
  //   name: "error_404",
  //   meta: {
  //     title: "页面不存在",
  //   },
  //   component: () => import("@/mixins/error/404.vue"),
  // },
  // {
  //   path: "*",
  //   name: "error_401",
  //   meta: {
  //     title: "没有权限访问",
  //   },
  //   component: () => import("@/mixins/error/401.vue"),
  // },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});
// 路由守卫
router.beforeEach(async (to, from, next) => {
  const url = window.location.hostname.replace('www.', '');
  // token相关
  const token = Token.get();
  // 路由排错
  if (to.matched.length === 0) {
    // 匹配前往的路由不存在
    from.name
      ? next({
        name: from.name,
      })
      : next({
        name: "error_404",
      }); // 判断此跳转路由的来源路由是否存在，存在的情况跳转到来源路由，否则跳转到404页面
  } else {
    if (!token) {
      window.location.href = "/login";
    } else {
      next();
      // 路由发生变化修改页面title
      if (to.meta.title) {
        document.title = `${to.meta.title} - ` + url;
      }
    }
  }
});

router.afterEach((to, from) => {
  if (to.name != from.name) {
    // window.scrollTo(0, 0);
    const container = document.querySelector(".content-area");
    if (container) {
      container.scrollTo(0, 0);
    }
  }
});

export default router;
